/**
* Created by wl
* 项目管理>持有中-详情页-财务数据-财务预期信息
*/
<template>
    <div class="ca-box ca-box-border-top-none ca-p-20">
        <div v-if="!showEdit">
            <div class="ca-title">
                <h3>财务预期</h3>
                <el-button type="text" class="ca-edit-btn el-icon-edit ca-m-r-10 edit-btn" @click="editInfo" :disabled="!isAuthIndexSee">编辑</el-button>
                <!-- <i class="el-icon-edit-outline edit-btn" @click="editInfo"></i> -->
            </div>
            <table class="ca-table ca-m-t-15" :model="list">
                <tr>
                    <th></th>
                    <th v-for="(item, index) in list" :key="index">{{item.particularYear}}</th>
                </tr>
                <tr>
                    <td>收入（万元）</td>
                    <td v-for="(item, index) in list" :key="index">{{item.income === '' ? '--': item.income | format1}}</td>
                </tr>
                <tr>
                    <td>收入完成度</td>
                    <td v-for="(item, index) in list" :key="index">{{item.incomeProportion  === '' ? '--': item.incomeProportion | format1}}%</td>
                </tr>
                <tr>
                    <td>利润（万元）</td>
                    <td v-for="(item, index) in list" :key="index">{{item.profit  === '' ? '--': item.profit | format1}}</td>
                </tr>
                <tr>
                    <td>利润完成度</td>
                    <td v-for="(item, index) in list" :key="index">{{item.profitProportion  === '' ? '--': item.profitProportion  | format1}}%</td>
                </tr>
            </table>
        </div>
        <csFinancialExpectation v-else :showBtn="true" @close="close" @save="save"></csFinancialExpectation>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { addRemind, isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                isAuthIndexSee: isNoAuth('持有中项目-财务数据-编辑'),
                showEdit: false,
                value: '',
                list: [],
            }
        },
        watch: {
        },
        props: {},
        created() {
            this.getInfo()
        },
        mounted() {
        },
        methods: {
            editInfo() {
                this.showEdit = true
            },
            close() {
                this.showEdit = false
            },
            async save() {
                this.showEdit = false
                await this.getInfo();
                // 添加小红点
                await addRemind({
                    dataId: this.$route.params.itemId, // 业务id
                    dataTab: 3, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 2, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            getInfo() {
                this.list = []
                apiHttp(api.CHECK_EXPECT, {itemId: this.$route.params.itemId}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        for (var i = 0; i < 5; i++) {
                            this.list.push({
                                particularYear: new Date().getFullYear() + i, //年份
                                income: '', //收入（万元)
                                incomeProportion: '', //收入完成度
                                profit: '', //利润（万元) ,
                                profitProportion: '', //利润完成度
                            })
                        }
                        ret.data.itemHoldFinanceExpects.map((item) => {
                            this.list.map((val,ind) => {
                                if (new Date(item.particularYear).getFullYear() === val.particularYear) {
                                    this.list[ind] = item
                                    this.list[ind].particularYear = new Date(item.particularYear).getFullYear()
                                }
                            })
                        })
                    }
                })
            },
        },
        components: {
            csFinancialExpectation: require('./edit'),
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.edit-btn {
    float: right;
    cursor: pointer
}
</style>